package com.example.repair

import android.os.Bundle
import androidx.activity.viewModels
import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat
import androidx.recyclerview.widget.LinearLayoutManager
import com.alibaba.android.arouter.facade.annotation.Route
import com.blankj.utilcode.util.ToastUtils
import com.example.common.view.view.BaseMvvmActivity
import com.example.repair.adapter.RepairAdapter
import com.example.repair.databinding.ActivityRepairListBinding
import com.example.repair.vm.RepairViewModel
import dagger.hilt.android.AndroidEntryPoint

@AndroidEntryPoint
@Route(path ="/repair/RepairListActivity")
class RepairListActivity : BaseMvvmActivity<ActivityRepairListBinding>() {
    override fun getLayoutId(): Int =R.layout.activity_repair_list
    val repairViewModel:RepairViewModel by viewModels ()
    val repairAdapter=RepairAdapter()
    override fun initView() {
        super.initView()
        repairViewModel.getRepair()
        mDataBinding.rv.adapter=repairAdapter
        mDataBinding.rv.layoutManager=LinearLayoutManager(this)
        repairViewModel.mSuccessLiveData.observe(this){
            repairAdapter.data.clear()
            repairAdapter.addData(it.data.sortedByDescending { it.id })
            repairAdapter.notifyDataSetChanged()
        }
        repairViewModel.mErrorLiveData.observe(this){
            ToastUtils.showLong(it)
        }
    }

}